package com.ktgj.other.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.other.domain.ChinaCity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.other.domain.RcCity;
import com.ktgj.other.service.IRcCityService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 专车城市Controller
 * 
 * @author ruoyi
 * @date 2022-07-27
 */
@RestController
@RequestMapping("/rcCity")
public class RcCityController extends BaseController
{
    @Autowired
    private IRcCityService rcCityService;

    /**
     * 查询专车城市列表
     */
    @PreAuthorize(hasPermi = "other:city:list")
    @GetMapping("/list")
    public TableDataInfo list(RcCity rcCity)
    {
        startPage();
        List<RcCity> list = rcCityService.selectRcCityList(rcCity);
        return getDataTable(list);
    }

    /**
     * 导出专车城市列表
     */
    @PreAuthorize(hasPermi = "other:city:export")
    @Log(title = "专车城市", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RcCity rcCity) throws IOException
    {
        List<RcCity> list = rcCityService.selectRcCityList(rcCity);
        ExcelUtil<RcCity> util = new ExcelUtil<RcCity>(RcCity.class);
        util.exportExcel(response, list, "专车城市数据");
    }

    /**
     * 获取专车城市详细信息
     */
    @PreAuthorize(hasPermi = "other:city:query")
    @GetMapping(value = "/{cityid}")
    public AjaxResult getInfo(@PathVariable("cityid") Long cityid)
    {
        return AjaxResult.success(rcCityService.selectRcCityById(cityid));
    }

    /**
     * 新增专车城市
     */
    @PreAuthorize(hasPermi = "other:city:add")
    @Log(title = "专车城市", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RcCity rcCity)
    {
        return toAjax(rcCityService.insertRcCity(rcCity));
    }

    /**
     * 修改专车城市
     */
    @PreAuthorize(hasPermi = "other:city:edit")
    @Log(title = "专车城市", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RcCity rcCity)
    {
        return toAjax(rcCityService.updateRcCity(rcCity));
    }

    /**
     * 删除专车城市
     */
    @PreAuthorize(hasPermi = "other:city:remove")
    @Log(title = "专车城市", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cityids}")
    public AjaxResult remove(@PathVariable Long[] cityids)
    {
        return toAjax(rcCityService.deleteRcCityByIds(cityids));
    }

    /**
     * 城市服务列表
     * @return
     */
    @PostMapping("/cityService")
    public AjaxResult cityService() {
        Map<String, List<Map<String, Object>>> map = rcCityService.cityService();
        return AjaxResult.success(map);
    }

    /**
     * 查询中国城市（市、县、州）
     * @return
     */
    @PostMapping("/queryCityList")
    public AjaxResult queryCityList() {
        List<ChinaCity> cityList = rcCityService.queryCityList();
        return AjaxResult.success(cityList);
    }
}
